package cn.hsa.xxx.bookData.controller;


import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import cn.hsa.xxx.api.dto.BookCommodityDTO;
import cn.hsa.xxx.api.service.BookCommodityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/web/bookData/bookCommodity")
@RestController
@Slf4j
public class BookCommodityController {

    @Autowired
    private BookCommodityService bookCommodityService;

    @PostMapping("/addBookCommodity")
    public WrapperResponse<BookCommodityDTO> addBookCommodity(@RequestBody BookCommodityDTO bookCommodityDTO) {
        BookCommodityDTO result = bookCommodityService.add(bookCommodityDTO);
        return WrapperResponse.success(result);
    }

    @PostMapping("/deleteBookCommodity")
    public WrapperResponse<String> deleteBookCommodity(@RequestParam String id) {
        String result = bookCommodityService.delete(id);
        return WrapperResponse.success(result);
    }

    @GetMapping("/getBookCommodityById")
    public WrapperResponse<BookCommodityDTO> getBookCommodity(@RequestParam String id) {
        BookCommodityDTO result = bookCommodityService.get(id);
        return WrapperResponse.success(result);
    }

    @PostMapping("/updateBookCommodity")
    public WrapperResponse<String> updateBookCommodity(@RequestBody BookCommodityDTO bookCommodityDTO) {
        String str = bookCommodityService.update(bookCommodityDTO);
        return WrapperResponse.success(str);
    }

    @GetMapping("/page")
    public WrapperResponse<List<BookCommodityDTO>> getPageBookCommodity(int pageNo, int pageSize) {
        List<BookCommodityDTO> bookCommodityDTOList = bookCommodityService.getPage(pageNo, pageSize);
        return WrapperResponse.success(bookCommodityDTOList);
    }
}
